import { addressData } from '../../../../data/address';
const app = getApp();
Page({
  data: {
    addressData,
    from:''
  },
  onLoad(option) {
    this.setData({
      addressData:addressData,
      from:option.from
    });
  },
  toEdit(e) {
    wx.navigateTo({
      url: '/pages/usercenter/address/edit/index?index='+e.currentTarget.dataset.index,
    });
  },
  toCommit(e) {
    if(this.data.from=='user_center')return;
    app.gData.currentAddress=addressData[e.currentTarget.dataset.index];
    wx.navigateTo({url: '/pages/cart/commit/index'});
  },
  addWXAddress(e) {
    wx.chooseAddress({
      success: async (options) => {
        const { provinceName, cityName, countyName, detailInfo, userName, telNumber } = options;
        let item = {
          rname: userName,
          phone: telNumber,
          area: provinceName+"/"+cityName+"/"+countyName,
          address: detailInfo,
          tag: -1
        };
        addressData.splice(1,0,item);
        wx.navigateTo({url: '/pages/usercenter/address/list/index'});
      }
    });
  },
  newAddress(e) {
    wx.navigateTo({url: '/pages/usercenter/address/edit/index?index=-1'});
  },
})
